home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
7_10.lha
/
7_10
/
qh_splice.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
2KB
|
58 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <process.h>
include <debug.h> /* DELETE */
* this qhead is supposed to be upstream to the qtail old_tail
add the contents of this's queue to old_tail's queue
destroy this, old_tail, and this's queue
alert the spliced qhead and qtail if a significant state change happened
/
oid queue_head::splice(queue_tail *old_tail)
if (debug) /*DELETE*/ cerr << "queue_head" << this << "::splice(" << old_tail << ")\n";
process_queue *tailsQ = old_tail->qt_queue;
process_queue *headsQ = qh_queue;
int tails_count = tailsQ->q_count;
int heads_count = headsQ->q_count;
tailsQ->q_count = 0;
/* either merge the two lists ... */
if (heads_count)
{
if (tails_count)
{
process_object *heads_last = headsQ->q_last;
process_object *tails_last = tailsQ->q_last;
process_object *tails_first = tails_last->po_next;
tails_last->po_next = heads_last->po_next;
heads_last->po_next = tails_first;
headsQ->q_count += tails_count;
}
}
/* ... or move the tail's queue to the head */
else
{
headsQ->q_count = tails_count;
headsQ->q_last = tailsQ->q_last;
tailsQ->q_last = 0;
}
/* patch tail's head onto head's queue */
headsQ->q_head = tailsQ->q_head;
tailsQ->q_head->qh_queue = headsQ;
tailsQ->q_head = 0;
qh_queue = 0;
/* delete the throwaways */
delete old_tail;
delete this;
/* alert the head if its queue becomes non-empty */
if ((tails_count == 0) && (heads_count > 0))
headsQ->q_head->alert();
if (debug) /*DELETE*/ cerr << "<<<< qhead" << this << "::splice(" << old_tail << ")\n";